/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.mine.presenter;

import android.text.TextUtils;
import android.widget.TextView;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.utils.ValidatorUtil;
import com.yiqi.lottery.entity.bo.BaseBo;
import com.yiqi.lottery.entity.bo.RegisterBo;
import com.yiqi.lottery.entity.bo.StationBo;
import com.yiqi.lottery.entity.bo.WithdrawBo;
import com.yiqi.lottery.feature.mine.contract.BindContract;
import com.yiqi.lottery.feature.mine.contract.StationContract;
import com.yiqi.lottery.feature.mine.dependencies.bind.DaggerBindPresenterComponent;
import com.yiqi.lottery.feature.mine.dependencies.station.DaggerStationPresenterComponent;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class StationPresenter implements StationContract.Presenter {

    private StationContract.View mView;

    @Inject

    StationContract.Model mModel;


    public StationPresenter(StationContract.View mView) {
        this.mView = mView;
        DaggerStationPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getStationInfo() {
        mModel.getStationInfo().compose(mView.bindToLife()).subscribe(new Observer<StationBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(StationBo baseBo) {
                mView.dismissLoading();
                mView.showStationInfoSuccess(baseBo);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void editWithDraw(String withdraw_account, String withdraw_name, String withdraw_phonw) {
        if (TextUtils.isEmpty(withdraw_account)){
              mView.showError("请输入您的银行卡号！");
              return;
        }
        if (TextUtils.isEmpty(withdraw_name)){
            mView.showError("请输入您的银行卡户名！");
            return;
        }
        if (TextUtils.isEmpty(withdraw_phonw)){
            mView.showError("请输入您的银行卡绑定的手机号！");
            return;
        }
        if (!ValidatorUtil.isMobile(withdraw_phonw)){
            mView.showError("请输入的手机号格式不正确！");
            return;
        }

        WithdrawBo withdrawBo=new WithdrawBo(withdraw_account,  withdraw_name,  withdraw_phonw);
        mModel.editWithDraw(withdrawBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }
            @Override
            public void onNext(String baseBo) {
                mView.dismissLoading();
                mView.showEditWithDrawSuccess(baseBo);
            }
            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }
            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });

    }

    @Override
    public void getWithDraw() {
         mModel.editWithDraw().compose(mView.bindToLife()).subscribe(new Observer<WithdrawBo>() {
             @Override
             public void onSubscribe(Disposable d) {
                 mView.showLoading(d);
             }
             @Override
             public void onNext(WithdrawBo baseBo) {
                 mView.dismissLoading();
                 mView.showGetWithDrawSuccess(baseBo);
             }
             @Override
             public void onError(Throwable e) {
                 mView.dismissLoading();
                 mView.showError(e.getMessage());
             }
             @Override
             public void onComplete() {
                 mView.dismissLoading();
             }
         });

    }
}
